#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>


typedef int stackTypeDate;

typedef struct Stack {
	stackTypeDate* a;
	int top;
	int capacity;
}ST;

void stackInit(ST* ps)
{
	ps->a = NULL;
	ps->top = ps->capacity = 0;
}

void stackPush(ST* ps, stackTypeDate x)
{
	assert(ps);
	if (ps->capacity == ps->top)
	{
		int newcapacity = ps->capacity == 0 ? 4 : 2 * ps->capacity;
		stackTypeDate* tmp = realloc(ps->a, newcapacity * sizeof(stackTypeDate));
		if (tmp == NULL)
		{
			printf("realloc fail");
			exit(-1);
		}
		ps->capacity = newcapacity;
		ps->a = tmp;
	}

	ps->a[ps->top] = x;
	ps->top++;
}

void stackPop(ST* ps)
{
	assert(ps);
	assert(ps->top > 0);
	ps->top--;
}

stackTypeDate stackFront(ST* ps)
{
	assert(ps);
	assert(ps->top > 0);
	return ps->a[ps->top - 1];
}

int stackSize(ST* ps)
{
	assert(ps);
	return ps->top;
}

bool stackEmpty(ST* ps)
{
	assert(ps);
	return ps->top == 0;
}

void stackDestroy(ST* ps)
{
	free(ps->a);
	ps->a = NULL;
	ps->top = ps->capacity = 0;
}
//=====================================================================ps
typedef struct {
	ST popStack;
	ST pushStack;
} MyQueue;


MyQueue* myQueueCreate() {
	MyQueue* tmp = (MyQueue*)malloc(sizeof(MyQueue));
	stackInit(&tmp->popStack);
	stackInit(&tmp->pushStack);
	return tmp;
}

void myQueuePush(MyQueue* obj, int x) {
	stackPush(&obj->pushStack, x);
}

int myQueuePop(MyQueue* obj) {
	if (stackEmpty(&obj->popStack))
	{
		while (!stackEmpty(&obj->pushStack))
		{
			stackPush(&obj->popStack, stackFront(&obj->pushStack));
			stackPop(&obj->pushStack);
		}
	}
	int x = stackFront(&obj->popStack);
	stackPop(&obj->popStack);
	return x;
}

int myQueuePeek(MyQueue* obj) {
	if (stackEmpty(&obj->popStack))
	{
		while (!stackEmpty(&obj->pushStack))
		{
			stackPush(&obj->popStack, stackFront(&obj->pushStack));
			stackPop(&obj->pushStack);
		}
	}
	return stackFront(&obj->popStack);
}

bool myQueueEmpty(MyQueue* obj) {
	return stackEmpty(&obj->popStack) && stackEmpty(&obj->pushStack);
}

void myQueueFree(MyQueue* obj) {
	stackDestroy(&obj->popStack);
	stackDestroy(&obj->pushStack);
	free(obj);
	obj = NULL;
}

/**
 * Your MyQueue struct will be instantiated and called as such:
 * MyQueue* obj = myQueueCreate();
 * myQueuePush(obj, x);

 * int param_2 = myQueuePop(obj);

 * int param_3 = myQueuePeek(obj);

 * bool param_4 = myQueueEmpty(obj);

 * myQueueFree(obj);
*/